<template>
  <div class="executor-dialog">
    <el-dialog :visible.sync="dialogFormVisible" :before-close="handleClose" :append-to-body="true" class="small-common-dialog-size">
      <template v-if="users && users.length">
        <Title :title="title" font-size="16px" style="margin-bottom: 24px;"/>
        <div class="user-list">
          <div v-for="(item, index) in users" :key="index" class="user-item">
            <div class="avatar-box">
              <div class="avatar">
                <user-card :user-data="item" :is-fly-notice="isFlyNotice" :size="42"/>
              </div>
              <div v-if="statusIcons[item.userStatus]" class="status-icon">
                <el-tooltip :open-delay="800" placement="top" effect="dark">
                  <div slot="content" style="max-width: 200px">
                    <div>状态：{{ statusToStr[item.userStatus] }}</div>
                    <div v-if="item.statusChangeTime">
                      时间：{{ item.statusChangeTime | format('YYYY/MM/DD HH:mm') }}
                    </div>
                  </div>
                  <img :src="statusIcons[item.userStatus]">
                </el-tooltip>
              </div>
              <!-- 抄送人已读 -->
              <div v-else-if="(!item.userStatus || [11, 12].includes(item.userStatus)) && item.isRead" class="status-icon">
                <el-tooltip :open-delay="800" placement="top" effect="dark">
                  <div slot="content" style="max-width: 200px">
                    <div>状态：已读</div>
                    <div v-if="item.statusChangeTime">
                      时间：{{ item.statusChangeTime | format('YYYY/MM/DD HH:mm') }}
                    </div>
                  </div>
                  <img :src="userStatus1">
                </el-tooltip>
              </div>
            </div>
            <div :title="item.userName" class="name ellipsisTwo">{{ item.userName }}</div>
          </div>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import Title from '@/components/Title';
import UserCard from '@/components/Common/userCard';
import userStatus1 from '@/assets/auditProcess/userStatus/status_1.png';
import userStatus2 from '@/assets/auditProcess/userStatus/status_2.png';
import userStatus3 from '@/assets/auditProcess/userStatus/status_3.png';
import userStatus4 from '@/assets/auditProcess/userStatus/status_4.png';
import userStatus5 from '@/assets/auditProcess/userStatus/status_5.png';
import { format } from '@/filters/date';

export default {
  components: {
    Title,
    UserCard
  },
  filters: { format },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    users: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      userStatus1,
      isFlyNotice: false
    };
  },
  computed: {
    statusIcons() {
      return {
        // 4 未读, 默认不展示角标
        5: userStatus1, // 已读
        0: userStatus2, // 未审批
        1: userStatus3, // 审批中
        2: userStatus4, // 已审批
        3: userStatus5 // 拒绝
      };
    },
    statusToStr() {
      return {
        0: '未审批',
        1: '处理中',
        2: '已处理',
        3: '未过审',
        5: '已读'
      };
    }
  },
  methods: {
    handleClose() {
      this.$emit('close');
      this.isFlyNotice = false;
    },
    initData(isFlyNotice) {
      this.isFlyNotice = isFlyNotice;
    }
  }
};
</script>
<style lang="scss" scoped>
.user-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  .user-item {
    flex-basis: 70px;
    // margin-right: 16px;
    margin-bottom: 18px;
    text-align: center;
    display: flex;
    align-items: center;
    flex-direction: column;
  }
  .avatar-box {
    width: 40px;
    height: 40px;
    position: relative;
    img {
      height: 100%;
      width: 100%;
    }
    .avatar {
      background: #DDE1EA;
      border: 1px solid #FFFFFF;
      border-radius: 50%;
      margin: 0 auto;
      // overflow: hidden;
      height: 100%;
      width: 100%;
    }
    .status-icon {
      position: absolute;
      display: flex;
      overflow: hidden;
      right: -4px;
      top: 0;
      width: 16px;
      height: 16px;
      z-index: 999;
      img:hover {
        cursor: pointer;
      }
    }
  }
  .name {
    font-size: 14px;
    line-height: 16px;
    color: #999;
    margin-top: 4px;
    height: 32px
  }
}
</style>
